// @author Nate
package dnablockfinder;

import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.Map;

public class DNABlockFinder {
	public static void main(String[] args) throws IOException {
		EvoNode evoTree = EvoNode.factory(args[1], createMap(args[2]));
		evoTree.analyze(Integer.parseInt(args[0]));
		evoTree.print(Paths.get(args[3]));
	}
	
	private static Map<String,String> createMap(String path) throws IOException {
		Map<String,String> dnaMap = new HashMap<>();
		String crrntKey = null;
		for (String fastaLine : Files
				.readAllLines(Paths.get(path), Charset.forName("US-ASCII")))
			if(fastaLine.startsWith(">")) {
				crrntKey = fastaLine.substring(1).trim();
				dnaMap.put(crrntKey, "");
			}	
			else
				dnaMap.put(crrntKey, dnaMap.get(crrntKey) + fastaLine);
		return dnaMap;
	}
}
